package iot.core.data.mapper;

import iot.core.data.BIdNameDto;
import iot.core.data.IdNameDto;
import iot.core.data.entity.HTUserRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HTUserRoleMapper extends MyBaseMapper<HTUserRole> {
    //获取关联角色
    @Select(value = {"select b.id,b.Name \n" +
            "from htuserrole a\n" +
            "inner join htrole b  on a.HTUser_Id =#{HTUser_Id} and a.Deleted=0  and a.HTDept_Id =#{HTDept_Id} and a.HTRole_Id =b.id and b.Deleted=0"})
    List<IdNameDto> getRole(Long HTUser_Id, Long HTDept_Id);

    @Select(value = {" <script> \n" +
            "select a.HTUser_Id as BId, b.id,b.Name \n" +
            "from htuserrole a\n" +
            "inner join htrole b  on a.HTUser_Id in \n" +
            "<foreach item=\"item\" index=\"index\" collection=\"lst\" open=\"(\" separator=\",\" close=\")\">  \n" +
            "     #{item}\n" +
            "    </foreach>  \n"+
            " and a.Deleted=0  and a.HTDept_Id =#{HTDept_Id} and a.HTRole_Id =b.id and b.Deleted=0\n"+
            " </script> \n"
    })
    List<BIdNameDto> getRoleByHTDept_IdAndIds(List<Long> lst, Long HTDept_Id);

}

